<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑优惠券区</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
        }
        .coupon-item {
            transition: all 0.3s ease;
        }
        .coupon-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
        }
        .drag-handle {
            cursor: move;
        }
    </style>
</head>
<body class="bg-gray-100">
    <div class="mx-auto max-w-[393px] h-[852px] bg-white relative overflow-hidden rounded-[40px] shadow-2xl">
        <!-- Status Bar -->
        <div class="bg-white px-6 pt-3 pb-2">
            <div class="flex justify-between items-center text-xs">
                <span class="font-semibold">9:41</span>
                <div class="flex space-x-1">
                    <i class="fas fa-signal"></i>
                    <i class="fas fa-wifi"></i>
                    <i class="fas fa-battery-full"></i>
                </div>
            </div>
        </div>

        <!-- Header -->
        <div class="bg-gradient-to-r from-orange-600 to-red-600 px-4 py-3">
            <div class="flex items-center justify-between text-white">
                <a href="b2b-store-decoration.html" class="text-white">
                    <i class="fas fa-arrow-left text-lg"></i>
                </a>
                <h1 class="text-lg font-semibold">编辑优惠券区</h1>
                <button onclick="saveCouponArea()" class="text-white hover:opacity-80">
                    <i class="fas fa-save text-lg"></i>
                </button>
            </div>
        </div>

        <!-- Coupon Preview -->
        <div class="p-4 bg-gray-50 border-b border-gray-200">
            <h3 class="text-sm font-medium text-gray-700 mb-2">预览效果</h3>
            <div class="bg-white rounded-lg p-3 shadow-sm">
                <h4 class="text-sm font-medium mb-2">新人专享优惠</h4>
                <div class="flex space-x-2 overflow-x-auto" id="couponPreview">
                    <div class="flex-shrink-0 bg-gradient-to-r from-red-500 to-pink-500 text-white rounded-lg p-2 text-center min-w-[80px]">
                        <p class="text-xs font-bold">¥20</p>
                        <p class="text-xs">满99使用</p>
                    </div>
                    <div class="flex-shrink-0 bg-gradient-to-r from-orange-500 to-yellow-500 text-white rounded-lg p-2 text-center min-w-[80px]">
                        <p class="text-xs font-bold">¥50</p>
                        <p class="text-xs">满299使用</p>
                    </div>
                    <div class="flex-shrink-0 bg-gradient-to-r from-green-500 to-teal-500 text-white rounded-lg p-2 text-center min-w-[80px]">
                        <p class="text-xs font-bold">8折</p>
                        <p class="text-xs">满500使用</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Coupon Management -->
        <div class="h-[calc(852px-320px)] overflow-y-auto pb-40">
            <!-- Coupon List -->
            <div class="p-4">
                <div class="flex items-center justify-between mb-3">
                    <h3 class="font-semibold flex items-center">
                        <span class="w-1 h-4 bg-orange-600 mr-2 rounded-full"></span>
                        优惠券列表 (5/8)
                    </h3>
                    <button onclick="addCoupon()" class="text-orange-600 text-sm hover:text-orange-700">
                        <i class="fas fa-plus mr-1"></i>添加优惠券
                    </button>
                </div>

                <div class="space-y-3" id="couponList">
                    <!-- Coupon 1 -->
                    <div class="coupon-item bg-white rounded-lg border border-gray-200 p-3">
                        <div class="flex items-center space-x-3">
                            <div class="drag-handle text-gray-400">
                                <i class="fas fa-grip-vertical"></i>
                            </div>
                            <div class="w-12 h-12 bg-gradient-to-r from-red-500 to-pink-500 rounded-lg flex items-center justify-center text-white">
                                <span class="text-xs font-bold">¥20</span>
                            </div>
                            <div class="flex-1">
                                <div class="flex items-center justify-between mb-1">
                                    <p class="text-sm font-medium">满99减20券</p>
                                    <span class="text-xs bg-green-100 text-green-600 px-2 py-1 rounded">已启用</span>
                                </div>
                                <p class="text-xs text-gray-500">有效期: 2025.01.05 - 2025.02.05</p>
                            </div>
                            <div class="flex space-x-2">
                                <button onclick="editCoupon(1)" class="text-blue-600 hover:text-blue-700">
                                    <i class="fas fa-edit text-sm"></i>
                                </button>
                                <button onclick="deleteCoupon(1)" class="text-red-600 hover:text-red-700">
                                    <i class="fas fa-trash text-sm"></i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- Coupon 2 -->
                    <div class="coupon-item bg-white rounded-lg border border-gray-200 p-3">
                        <div class="flex items-center space-x-3">
                            <div class="drag-handle text-gray-400">
                                <i class="fas fa-grip-vertical"></i>
                            </div>
                            <div class="w-12 h-12 bg-gradient-to-r from-orange-500 to-yellow-500 rounded-lg flex items-center justify-center text-white">
                                <span class="text-xs font-bold">¥50</span>
                            </div>
                            <div class="flex-1">
                                <div class="flex items-center justify-between mb-1">
                                    <p class="text-sm font-medium">满299减50券</p>
                                    <span class="text-xs bg-green-100 text-green-600 px-2 py-1 rounded">已启用</span>
                                </div>
                                <p class="text-xs text-gray-500">有效期: 2025.01.05 - 2025.02.05</p>
                            </div>
                            <div class="flex space-x-2">
                                <button onclick="editCoupon(2)" class="text-blue-600 hover:text-blue-700">
                                    <i class="fas fa-edit text-sm"></i>
                                </button>
                                <button onclick="deleteCoupon(2)" class="text-red-600 hover:text-red-700">
                                    <i class="fas fa-trash text-sm"></i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- Coupon 3 -->
                    <div class="coupon-item bg-white rounded-lg border border-gray-200 p-3">
                        <div class="flex items-center space-x-3">
                            <div class="drag-handle text-gray-400">
                                <i class="fas fa-grip-vertical"></i>
                            </div>
                            <div class="w-12 h-12 bg-gradient-to-r from-green-500 to-teal-500 rounded-lg flex items-center justify-center text-white">
                                <span class="text-xs font-bold">8折</span>
                            </div>
                            <div class="flex-1">
                                <div class="flex items-center justify-between mb-1">
                                    <p class="text-sm font-medium">满500享8折</p>
                                    <span class="text-xs bg-green-100 text-green-600 px-2 py-1 rounded">已启用</span>
                                </div>
                                <p class="text-xs text-gray-500">有效期: 2025.01.05 - 2025.01.31</p>
                            </div>
                            <div class="flex space-x-2">
                                <button onclick="editCoupon(3)" class="text-blue-600 hover:text-blue-700">
                                    <i class="fas fa-edit text-sm"></i>
                                </button>
                                <button onclick="deleteCoupon(3)" class="text-red-600 hover:text-red-700">
                                    <i class="fas fa-trash text-sm"></i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- Coupon 4 -->
                    <div class="coupon-item bg-white rounded-lg border border-gray-200 p-3">
                        <div class="flex items-center space-x-3">
                            <div class="drag-handle text-gray-400">
                                <i class="fas fa-grip-vertical"></i>
                            </div>
                            <div class="w-12 h-12 bg-gradient-to-r from-purple-500 to-indigo-500 rounded-lg flex items-center justify-center text-white">
                                <span class="text-xs font-bold">¥100</span>
                            </div>
                            <div class="flex-1">
                                <div class="flex items-center justify-between mb-1">
                                    <p class="text-sm font-medium">满999减100券</p>
                                    <span class="text-xs bg-gray-100 text-gray-600 px-2 py-1 rounded">已禁用</span>
                                </div>
                                <p class="text-xs text-gray-500">有效期: 2025.01.10 - 2025.03.10</p>
                            </div>
                            <div class="flex space-x-2">
                                <button onclick="editCoupon(4)" class="text-blue-600 hover:text-blue-700">
                                    <i class="fas fa-edit text-sm"></i>
                                </button>
                                <button onclick="deleteCoupon(4)" class="text-red-600 hover:text-red-700">
                                    <i class="fas fa-trash text-sm"></i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- Coupon 5 -->
                    <div class="coupon-item bg-white rounded-lg border border-gray-200 p-3">
                        <div class="flex items-center space-x-3">
                            <div class="drag-handle text-gray-400">
                                <i class="fas fa-grip-vertical"></i>
                            </div>
                            <div class="w-12 h-12 bg-gradient-to-r from-pink-500 to-rose-500 rounded-lg flex items-center justify-center text-white">
                                <span class="text-xs font-bold">免邮</span>
                            </div>
                            <div class="flex-1">
                                <div class="flex items-center justify-between mb-1">
                                    <p class="text-sm font-medium">包邮券</p>
                                    <span class="text-xs bg-green-100 text-green-600 px-2 py-1 rounded">已启用</span>
                                </div>
                                <p class="text-xs text-gray-500">有效期: 长期有效</p>
                            </div>
                            <div class="flex space-x-2">
                                <button onclick="editCoupon(5)" class="text-blue-600 hover:text-blue-700">
                                    <i class="fas fa-edit text-sm"></i>
                                </button>
                                <button onclick="deleteCoupon(5)" class="text-red-600 hover:text-red-700">
                                    <i class="fas fa-trash text-sm"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Display Settings -->
            <div class="p-4">
                <h3 class="font-semibold mb-3 flex items-center">
                    <span class="w-1 h-4 bg-orange-600 mr-2 rounded-full"></span>
                    展示设置
                </h3>
                <div class="bg-white rounded-lg border border-gray-200 p-4">
                    <div class="space-y-4">
                        <!-- Section Title -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">区域标题</label>
                            <input type="text" id="areaTitle" value="新人专享优惠" 
                                   class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-transparent">
                        </div>

                        <!-- Layout Style -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">显示样式</label>
                            <div class="grid grid-cols-2 gap-2">
                                <button class="p-3 border border-orange-500 rounded-lg bg-orange-50" onclick="selectCouponStyle('horizontal')">
                                    <div class="flex space-x-1 mb-2">
                                        <div class="w-8 h-6 bg-orange-300 rounded"></div>
                                        <div class="w-8 h-6 bg-orange-300 rounded"></div>
                                        <div class="w-8 h-6 bg-orange-300 rounded"></div>
                                    </div>
                                    <p class="text-xs">横向滚动</p>
                                </button>
                                <button class="p-3 border border-gray-300 rounded-lg" onclick="selectCouponStyle('grid')">
                                    <div class="grid grid-cols-2 gap-1 mb-2">
                                        <div class="w-full h-4 bg-gray-300 rounded"></div>
                                        <div class="w-full h-4 bg-gray-300 rounded"></div>
                                        <div class="w-full h-4 bg-gray-300 rounded"></div>
                                        <div class="w-full h-4 bg-gray-300 rounded"></div>
                                    </div>
                                    <p class="text-xs">网格布局</p>
                                </button>
                            </div>
                        </div>

                        <!-- Show Count -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">显示优惠券数量</label>
                            <select id="showCount" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-transparent">
                                <option value="3" selected>3个</option>
                                <option value="4">4个</option>
                                <option value="5">5个</option>
                                <option value="all">全部显示</option>
                            </select>
                        </div>

                        <!-- Auto Scroll -->
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-sm font-medium">自动滚动</p>
                                <p class="text-xs text-gray-500">横向滚动时自动切换</p>
                            </div>
                            <label class="relative inline-flex items-center cursor-pointer">
                                <input type="checkbox" checked class="sr-only peer" id="autoScroll">
                                <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-orange-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-orange-600"></div>
                            </label>
                        </div>

                        <!-- Show Get Button -->
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-sm font-medium">显示领取按钮</p>
                                <p class="text-xs text-gray-500">每个优惠券显示领取按钮</p>
                            </div>
                            <label class="relative inline-flex items-center cursor-pointer">
                                <input type="checkbox" checked class="sr-only peer" id="showGetButton">
                                <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-orange-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-orange-600"></div>
                            </label>
                        </div>

                        <!-- Background Style -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">背景样式</label>
                            <div class="grid grid-cols-3 gap-2">
                                <button class="p-2 border border-orange-500 rounded-lg bg-gradient-to-r from-red-500 to-pink-500" onclick="selectBackground('red')">
                                    <p class="text-xs text-white">红色渐变</p>
                                </button>
                                <button class="p-2 border border-gray-300 rounded-lg bg-gradient-to-r from-orange-500 to-yellow-500" onclick="selectBackground('orange')">
                                    <p class="text-xs text-white">橙色渐变</p>
                                </button>
                                <button class="p-2 border border-gray-300 rounded-lg bg-gradient-to-r from-purple-500 to-indigo-500" onclick="selectBackground('purple')">
                                    <p class="text-xs text-white">紫色渐变</p>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- User Restrictions -->
            <div class="p-4">
                <h3 class="font-semibold mb-3 flex items-center">
                    <span class="w-1 h-4 bg-orange-600 mr-2 rounded-full"></span>
                    用户限制
                </h3>
                <div class="bg-white rounded-lg border border-gray-200 p-4">
                    <div class="space-y-4">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-sm font-medium">仅新用户可见</p>
                                <p class="text-xs text-gray-500">只对新注册用户显示</p>
                            </div>
                            <label class="relative inline-flex items-center cursor-pointer">
                                <input type="checkbox" checked class="sr-only peer" id="newUserOnly">
                                <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-orange-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-orange-600"></div>
                            </label>
                        </div>

                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-sm font-medium">VIP专享</p>
                                <p class="text-xs text-gray-500">VIP会员额外优惠</p>
                            </div>
                            <label class="relative inline-flex items-center cursor-pointer">
                                <input type="checkbox" class="sr-only peer" id="vipOnly">
                                <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-orange-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-orange-600"></div>
                            </label>
                        </div>

                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">每人限领数量</label>
                            <select id="limitPerUser" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-transparent">
                                <option value="1" selected>每人限领1张</option>
                                <option value="3">每人限领3张</option>
                                <option value="5">每人限领5张</option>
                                <option value="unlimited">不限制</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Fixed Bottom Action Bar -->
        <div class="absolute bottom-1 left-0 right-0 bg-white border-t border-gray-200 p-4">
            <div class="flex space-x-3">
                <button onclick="previewCouponArea()" class="bg-gray-100 text-gray-700 font-medium px-4 py-3 rounded-xl hover:bg-gray-200 transition-colors">
                    <i class="fas fa-eye mr-2"></i>预览
                </button>
                <button onclick="saveCouponArea()" class="flex-1 bg-gradient-to-r from-orange-600 to-red-600 text-white font-medium py-3 rounded-xl shadow-lg hover:shadow-xl transition-all duration-200">
                    <i class="fas fa-save mr-2"></i>保存设置
                </button>
            </div>
        </div>
    </div>

    <script>
        // Coupon area management functions
        function addCoupon() {
            if (document.querySelectorAll('.coupon-item').length >= 8) {
                showToast('最多只能添加8张优惠券');
                return;
            }
            
            const couponTypes = [
                { type: '满减券', amount: '¥30', condition: '满199减30' },
                { type: '折扣券', amount: '9折', condition: '满399享9折' },
                { type: '免邮券', amount: '免邮', condition: '全场包邮' },
                { type: '新人券', amount: '¥10', condition: '新人专享10元' }
            ];
            
            const choice = prompt('选择优惠券类型：\n\n1. 满减券\n2. 折扣券\n3. 免邮券\n4. 新人券\n\n请输入序号 (1-4):');
            
            if (choice >= 1 && choice <= 4) {
                const selected = couponTypes[choice - 1];
                showToast(`正在添加${selected.type}...`);
                setTimeout(() => {
                    showToast('优惠券添加成功');
                    updateCouponCount();
                }, 1000);
            }
        }

        function editCoupon(id) {
            const options = [
                '修改优惠金额',
                '设置使用条件',
                '调整有效期',
                '编辑显示样式',
                '启用/禁用'
            ];
            
            const choice = prompt(`编辑优惠券选项：\n\n1. ${options[0]}\n2. ${options[1]}\n3. ${options[2]}\n4. ${options[3]}\n5. ${options[4]}\n\n请输入序号 (1-5):`);
            
            if (choice >= 1 && choice <= 5) {
                showToast(`正在${options[choice - 1]}...`);
                setTimeout(() => {
                    showToast('编辑完成');
                }, 1000);
            }
        }

        function deleteCoupon(id) {
            if (confirm('确认删除这张优惠券吗？\n\n删除后无法恢复，已领取的用户不受影响。')) {
                showToast('正在删除优惠券...');
                setTimeout(() => {
                    showToast('优惠券已删除');
                    updateCouponCount();
                }, 1000);
            }
        }

        function updateCouponCount() {
            const count = document.querySelectorAll('.coupon-item').length;
            document.querySelector('h3 .font-semibold').innerHTML = `
                <span class="w-1 h-4 bg-orange-600 mr-2 rounded-full"></span>
                优惠券列表 (${count}/8)
            `;
        }

        function selectCouponStyle(style) {
            // Remove selected state from all buttons
            document.querySelectorAll('[onclick^="selectCouponStyle"]').forEach(btn => {
                btn.className = 'p-3 border border-gray-300 rounded-lg';
            });
            
            // Add selected state to clicked button
            event.target.closest('button').className = 'p-3 border border-orange-500 rounded-lg bg-orange-50';
            
            showToast(`已选择${style === 'horizontal' ? '横向滚动' : '网格布局'}样式`);
        }

        function selectBackground(color) {
            // Remove selected state from all buttons
            document.querySelectorAll('[onclick^="selectBackground"]').forEach(btn => {
                btn.className = btn.className.replace('border-orange-500', 'border-gray-300');
            });
            
            // Add selected state to clicked button
            const button = event.target.closest('button');
            button.className = button.className.replace('border-gray-300', 'border-orange-500');
            
            const colorNames = {
                'red': '红色渐变',
                'orange': '橙色渐变',
                'purple': '紫色渐变'
            };
            
            showToast(`已选择${colorNames[color]}背景`);
        }

        function previewCouponArea() {
            showToast('正在生成优惠券区域预览...');
            setTimeout(() => {
                showToast('预览功能开发中，敬请期待');
            }, 1000);
        }

        function saveCouponArea() {
            const settings = {
                areaTitle: document.getElementById('areaTitle').value,
                showCount: document.getElementById('showCount').value,
                autoScroll: document.getElementById('autoScroll').checked,
                showGetButton: document.getElementById('showGetButton').checked,
                newUserOnly: document.getElementById('newUserOnly').checked,
                vipOnly: document.getElementById('vipOnly').checked,
                limitPerUser: document.getElementById('limitPerUser').value
            };

            showToast('正在保存优惠券区域设置...');
            
            setTimeout(() => {
                showToast('优惠券区域设置保存成功！');
                setTimeout(() => {
                    window.location.href = 'b2b-store-decoration.html';
                }, 1000);
            }, 1500);
        }

        // Toast notification
        function showToast(message) {
            const toast = document.createElement('div');
            toast.className = 'fixed top-20 left-1/2 transform -translate-x-1/2 bg-gray-800 text-white px-4 py-2 rounded-lg text-sm z-50';
            toast.textContent = message;
            document.body.appendChild(toast);
            
            setTimeout(() => {
                toast.remove();
            }, 2000);
        }

        // Initialize page
        document.addEventListener('DOMContentLoaded', function() {
            showToast('优惠券区域编辑器已加载');
        });
    </script>
</body>
</html>